//
//  FFlexibleDesignView.m
//  ForestPack
//
//  Created by jimmy on 2018/7/9.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "FFlexibleDesignView.h"
#import "HMSegmentedControl.h"

@interface FFlexibleDesignView()

@property (nonatomic,assign)NSInteger  type;

@end


@implementation FFlexibleDesignView

- (instancetype)initWithType:(NSInteger)type
{
    self = [super init];
    if (self) {
        self.type = type;
        [self initViewUI];
    }
    return self;
}

- (void)initViewUI
{
    [self setSegmentUI];
    [self initTableViewUI];
}

-(void)segmentDidChangedValue
{
    if (_segmentClick) {
        _segmentClick();
    }
}

- (void)setSegmentUI{
    
    if (self.type == 1000) {
        // 全部
        return;
    }
    NSArray * titleAry = @[];
    
    if (self.type == 1001) {
        titleAry = @[@"综合",@"成交",@"好评",@"区域",@"筛选"];
    }else if (self.type == 1002)
    {
        titleAry = @[@"综合",@"价格",@"区域",@"筛选"];
    }else
    {
        titleAry = @[@"综合",@"价格",@"区域",@"筛选"];
    }

    // 设置 segement
    HMSegmentedControl  * segControl = [[HMSegmentedControl alloc] initWithSectionTitles:titleAry];
    segControl.backgroundColor = RGB_COLOR(238,238,238);
    segControl.selectionStyle = HMSegmentedControlSelectionStyleTextWidthStripe;
    segControl.autoresizingMask = UIViewAutoresizingFlexibleWidth |  UIViewAutoresizingFlexibleRightMargin;
    segControl.titleTextAttributes = @{NSForegroundColorAttributeName:RGB_COLOR(153,153,153),NSFontAttributeName:[UIFont fontWithName:@"PingFangSC-Regular" size:14]};
    //设置选项卡被选中的颜色
    segControl.selectedTitleTextAttributes = @{NSForegroundColorAttributeName:RGB_COLOR(237,34,59),NSFontAttributeName:[UIFont fontWithName:@"PingFangSC-Regular" size:14]};
    segControl.selectionIndicatorLocation = HMSegmentedControlSelectionIndicatorLocationDown;
    segControl.selectionIndicatorHeight = 0;
    //设置开始时默认选中的下标
    segControl.selectedSegmentIndex = 0;
    //设置选中的选项卡的点击事件
    [segControl addTarget:self action:@selector(segmentDidChangedValue) forControlEvents:UIControlEventValueChanged];
    [self addSubview:segControl];
    
}

- (void)initTableViewUI
{
    CGFloat top = 0;
    if (self.type != 1000) {
        top = 30;
    }
    UITableView * tableView = [[UITableView alloc] initWithFrame:CGRectMake((self.type - 1000) * SCREEN_WIDTH , top, SCREEN_WIDTH, SCREEN_WIDTH - top - TAB_BAR_HEIGHT)];
    tableView.showsVerticalScrollIndicator = NO;
    tableView.showsHorizontalScrollIndicator = NO;
    tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    [self addSubview:tableView];
    
}



@end
